package com.compty.paint.web;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpSession;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;

import com.compty.paint.util.Constants;

/**
 * @Todo:检查前端用户是否登录自定义标签,未登录即跳转登录页面
 * @author: 朱庆辉
 * @CreateTime:2012-3-19 下午02:12:53
 */
public class CustomerLogonCheckTag extends TagSupport {

	private static final long serialVersionUID = 6052345495005763008L;
	
	private final String login_url = "/u_login.jsp";

	@Override
	public int doStartTag() throws JspException {
		// TODO Auto-generated method stub
		HttpSession session = pageContext.getSession();
		
		Object customerInfo =  session.getAttribute(Constants.CustomerInfo);
		if ( customerInfo == null ) {
			try {
				pageContext.forward(login_url);
			} catch (ServletException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
		return super.doStartTag();
	}
	
}
